package com.example.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.wheelview.PicPopupWindow;
import com.orhanobut.android.dialogplussample.R;
import com.orhanobut.dialogplus.DialogPlus;
import com.orhanobut.dialogplus.ViewHolder;

/**
 * @ClassName: DialogUtils
 * @Description: 弹窗工具类
 * @Date: 2020/5/26 17:06
 * @Author: kalinaji
 */
public class DialogUtils {


    /**
     * 基本弹窗
     *
     * @param context 上下文
     * @param title   标题
     * @param message 内容
     */
    public static DialogPlus baseDialog(Context context, String title, String message, Intent intent) {

        DialogPlus dialogPlus = DialogPlus
                .newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.new_content_base))
                .setGravity(Gravity.CENTER)
                .setContentHeight(600)
                .setPadding(10, 10, 10, 10)
                .create();

        View view = dialogPlus.getHolderView();
        TextView TvTitle = view.findViewById(R.id.tv_title);
        TvTitle.setText(title);
        TextView TvContent = view.findViewById(R.id.tv_content);
        TvContent.setText(message);
        view.findViewById(R.id.btn_left).setOnClickListener(v -> dialogPlus.dismiss());
        view.findViewById(R.id.btn_right).setOnClickListener(v -> {
            context.startActivity(intent);
            dialogPlus.dismiss();
        });
        return dialogPlus;
    }

    /**
     * 进度条
     *
     * @param context 上下文
     */
    public static void loadDialog(Context context) {

        DialogPlus
                .newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.new_content_loading))
                .setContentBackgroundResource(R.color.tr)
                .setContentHeight(600)
                .setGravity(Gravity.CENTER)
                .create()
                .show();
    }

    /**
     * 日期弹窗
     *
     * @param context 上下文
     */
    public static DialogPlus dateDialog(Activity context,Button button) {

        DialogPlus dialogPlus = DialogPlus
                .newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.new_content_date))
                .setGravity(Gravity.TOP)
                .setContentHeight(600)
                .create();

        // 主体视图
        View view = dialogPlus.getHolderView();

        // 窗体
        PicPopupWindow mPopupWindow = new PicPopupWindow(context);
        mPopupWindow.addContentView(view);

        view.findViewById(R.id.btn_ok).setOnClickListener(v -> {
            String s = mPopupWindow.getYear() +
                            "-" +
                    mPopupWindow.getMonth() +
                            "-" +
                            mPopupWindow.getDay();
            button.setText(s);
            dialogPlus.dismiss();
        });
        return dialogPlus;
    }



}
